<template>
  <Card>
    <div style="overflow: hidden; height: 40px;">
      <Input v-model="searchValue" search enter-button placeholder="请输入关键字……" style="float: right; width: 250px;" @on-change="getFactories"/>
    </div>
    <Table :columns="columns" :data="dataList" style="margin-top: 10px;"></Table>
    <div class="page">
      <Page :total="pageTotal" :page-size="pageSize" :current="pageNum" @on-change="changePage"></Page>
    </div>
  </Card>
</template>

<script>
  export default {
    name: "Factory",
    data() {
      return {
        // 页码
        pageNum: 1,
        // 页大小
        pageSize: 10,
        // 页总数
        pageTotal: 0,
        // 搜索信息
        searchValue: "",
        // 表数据
        dataList: [],
        // 表头
        columns: [
          {
            title: "编号",
            key: "id"
          }, {
            title: "厂商名称",
            key: "factoryName"
          }, {
            title: "地址",
            key: "address"
          }, {
            title: "联系人",
            key: "people"
          }, {
            title: "联系方式",
            key: "relations"
          }, {
            title: "操作",
            key: "action",
            width: 250,
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary'
                  },
                  on: {
                    click: () => {
                      this.$router.push({
                        path:"/order/good",
                        query:{
                          factory: params.row.id,
                        }
                      });
                    }
                  }
                }, '查看商品')
              ])
            }
          }
        ],
      }
    },
    methods: {
      // 翻页
      changePage (pageNo) {
        // 更改当前页
        this.pageNum = pageNo;
        // 重新获取数据
        this.getFactories();
      },
      getFactories() {
        this.$requests.get("/factory/getAllFactories", {
          search: this.searchValue,
          pageNum: this.pageNum,
          pageSize: this.pageSize
        }).then(res => {
          if (res.data.code === 0) {
            this.dataList = res.data.data.list;
            this.pageTotal = res.data.data.total;
            this.pageNum = res.data.data.pageNum;
          } else {
            this.$Message.error(res.data.msg);
          }
        })
      }
    },
    created() {
      this.getFactories();
    }
  }
</script>

<style scoped>
  .page {
    margin-top: 10px;
    text-align: right;
  }
</style>
